package com.mp.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mp.pojo.Query.UserinfoSearchQuery;
import com.mp.pojo.UserInfo;
import com.mp.pojo.VO.UserInfoSearchVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author jack
 * @data 2019-08-09 14:33
 */
public interface UserInfoMapper extends BaseMapper<UserInfo> {

    @Select("select count(mc.phone)  as phone_count,count(mc.msg)  as msg_count,count(mc.phone) + count(mc.msg) as request_count," +
            "count(mc.msg) * u.msg_fee as total_consumption,round(ifnull(count(mc.msg)/count(mc.phone),0),4) as success_rate," +
            "    u.* from user_info u left join msg_code mc on u.id = mc.user_id group by u.id ${ew.customSqlSegment}")
    IPage<UserInfoSearchVO> getPageBySeach(Page<UserInfo> page, @Param(Constants.WRAPPER) Wrapper<UserInfo> wrapper);
}
